package com.hangsu.train.components.web.utils;

import com.hangsu.train.components.entity.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.subject.Subject;

public class UserUtils {

    public static User getCurrUser() {
        Subject subject = SecurityUtils.getSubject();
        if (subject.isAuthenticated() && subject.getPrincipal() != null) {
            return (User) SecurityUtils.getSubject().getPrincipal();
        }
        throw new AuthenticationException("用户未登录");
    }
}
